﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DevComponents.DotNetBar;
using DevComponents.DotNetBar.Controls;
using StuMana.Services;

namespace StuMana.UI
{
    public partial class Preview : Office2007Form
    {
        public Preview()
        {
            InitializeComponent();
            
        }

        public StuMana.Services.student stu;
        public string query;
        public string previewName;

        public void LoadData()
        {
            ConnectionController control = new ConnectionController();
            control.connection.Open();
            try
            {
                MySql.Data.MySqlClient.MySqlCommand cmd = control.connection.CreateCommand();
                cmd.CommandText = query;
                MySql.Data.MySqlClient.MySqlDataAdapter adap = new MySql.Data.MySqlClient.MySqlDataAdapter(cmd);
                DataSet ds = new DataSet();
                adap.Fill(ds);
                dgvData.DataSource = ds.Tables[0].DefaultView;

            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                if (control.connection.State == ConnectionState.Open)
                    control.connection.Clone();
            }
        }

        private void Preview_Load(object sender, EventArgs e)
        {
            lblTagID.Text = stu.TagID.ToString();
            lblName.Text = stu.Name.ToString();
            lblClass.Text = stu.Class.ToString();
            lblAcount.Text = stu.Account.ToString();
            lblPreviewName.Text = previewName;

            string ngay,thang,nam;
            ngay=DateTime.Today.Day.ToString();
            thang=DateTime.Today.Month.ToString();
            nam=DateTime.Today.Year.ToString();
            lblNgayThangNam.Text = " Ngày " + ngay + "  tháng " + thang + " năm " + nam;

            LoadData();
            if (dgvData.Columns.Count > 0)
            {
                int w1 = dgvData.Size.Width;
                int widthC1 = ((int)w1 / dgvData.Columns.Count);

                for (int i = 0; i < dgvData.Columns.Count; i++)
                {
                    dgvData.Columns[i].Width = widthC1;
                }
            }
        }

        private void btnExit_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void Preview_Resize(object sender, EventArgs e)
        {
            int wPanel = this.panelExPreview.Size.Width;
            int hPanel = this.panelExPreview.Size.Height;

            int w2Panel = ((int)(wPanel / 2));
            int h2Panel = ((int)(hPanel / 2));

            int wPanel2 = this.gPanelMiddle.Size.Width;
            int hPanel2 = this.gPanelMiddle.Size.Height;

            int w2Panel2 = ((int)(wPanel2 / 2));
            int h2Panel2 = ((int)(hPanel2 / 2));

            int x = w2Panel - w2Panel2;
            int y = h2Panel - h2Panel2;

            this.gPanelMiddle.Location = new Point(x, y);
            if (dgvData.Columns.Count > 0)
            {
                int w1 = dgvData.Size.Width;
                int widthC1 = ((int)w1 / dgvData.Columns.Count);

                for (int i = 0; i < dgvData.Columns.Count; i++)
                {
                    dgvData.Columns[i].Width = widthC1;
                }
            }
        }
    }
}
